import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import home from '@/components/home'
import user from '@/components/userPanel'
import character from '@/components/characterPanel'
import hello from '@/components/Hello'
import department from '@/components/departmentPanel'
import classPanel from '@/components/classPanel'
import course from '@/components/coursePanel'
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Index',
      component: index
    },
    {
      path: '/login',
      name: 'Login',
      component: index
    },
    {
      path: '/home',
      name: 'Home',
      beforeEnter: (to, from, next) => {
        if (sessionStorage.getItem('token')) {
          next()
        } else {
          next('/login')
        }
      },
      component: home,
      meta: {
        isLogin: true
      },
      children: [
        {
          path: "/home/user",
          name: "用户管理",
          component: user
        },
        {
          path: "/home/character",
          name: "角色管理",
          component: character
        },
        {
          path: "/home/department",
          name: "部门管理",
          component: department
        },
        {
          path: "/home/classPanel",
          name: "班级管理",
          component: classPanel
        },
        {
          path: "/home/course",
          name: "课程管理",
          component: course
        },
        {
          path: "/home/hello",
          name: "welcome",
          component: hello
        }
      ]
    }
  ]
})
